package com.sxg.controller;

import com.sxg.query.SxgUserQuery;
import com.sxg.utils.code.AjaxResult;
import com.sxg.vo.SxgUserVO;
import com.sxg.vo.resp.ModifyPasswordReqVo;
import lombok.AllArgsConstructor;
import com.sxg.page.PageResult;
import com.sxg.utils.code.Result;
import com.sxg.service.SxgUserService;
import org.springframework.web.bind.annotation.*;

import jakarta.validation.Valid;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * 用户表
 *
 * @author 浪漫写尽歌谱 3298751420@qq.com
 * @since 1.0.0 2024-03-07
 */
@RestController
@RequestMapping("sxg/sxg_user")
@AllArgsConstructor
public class SxgUserController {
    private final SxgUserService sxgUserService;

    @GetMapping("page")
    public Result<PageResult<SxgUserVO>> page(@Valid SxgUserQuery query) {
        PageResult<SxgUserVO> page = sxgUserService.page(query);
        return Result.ok(page);
    }

    @GetMapping("info")
    public AjaxResult getUserInfo() {
        return AjaxResult.success(sxgUserService.getUserInfo());
    }

    public Result<String> save(@RequestBody SxgUserVO vo) {
        sxgUserService.save(vo);

        return Result.ok();
    }

    @PutMapping
    public AjaxResult update(@RequestBody @javax.validation.Valid SxgUserVO vo) {
        return sxgUserService.updateInfo(vo);
    }

    @PostMapping("modifyPassword")
    public AjaxResult modifyPassword(@RequestBody @Valid ModifyPasswordReqVo vo) {
        return sxgUserService.modifyPassword(vo);
    }

    public Result<String> delete(@RequestBody List<Long> idList) {
        sxgUserService.delete(idList);
        return Result.ok();
    }

    @PostMapping("avatar")
    public AjaxResult avatar(@RequestParam("file") MultipartFile file) {
        return sxgUserService.avatar(file);
    }
}